import argparse
import os

from aspose.words import Document, SaveFormat

parser = argparse.ArgumentParser(description='PDF to EPUB converter')
parser.add_argument('input_folder', help='Input folder path')
args = parser.parse_args()


def is_pdf(file_path):
    """确定输入文件的类型是否是pdf

    Args:
        file_path (_type_): 文件路径

    Returns:
        _type_: _description_
    """
    return file_path.endswith('.pdf')



for root, dirs, files in os.walk(args.input_folder):
    """转换所有pdf文件

    Args:
        file_path (_type_): _description_
        dirs (_type_): _description_
        filesinos (_type_): _description_
    """
    for file in files:
        if is_pdf(os.path.join(root, file)):
            print(f"开始转换 {os.path.splitext(file)[0]}")
            output_file = os.path.splitext(args.input_folder)[0] + '.epub'
            doc = Document(os.path.join(root, file))
            doc.save(output_file)
            print(f"{output_file} 转换完成")
